package com.ymatou.iapi.trading.operate.testcase;

import java.math.BigDecimal;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.BargainGroupService;
import com.ymatou.iapi.trading.operate.parameter.Order;
import com.ymatou.iapi.trading.operate.parameter.OrderInfoPo;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderService;
import com.ymatou.iapi.trading.operate.parameter.req.ApplySalesRefundRequestBean;
import com.ymatou.iapi.trading.operate.parameter.req.ApplyValidationBean;
import com.ymatou.iapi.trading.operate.service.ApplySalesRefundRequestCall;
import com.ymatou.iapi.trading.operate.service.ApplyValidationCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.common.enums.CancelOrderTypeEnum;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.constant.ECode;

/**
 * 退货退款申请效验接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_ApplyValidation {
	private static ApplyValidationBean applyvalidationBean;
	private static ApplyValidationCall applyvalidationCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("退货退款申请校验接口");
	}

	@Before
	public void caseUp() {
		applyvalidationBean = new ApplyValidationBean();
		applyvalidationCall = new ApplyValidationCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(applyvalidationCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ApplyValidation_001() {
		Logger.start(true, "用户下单后申请效验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setCatalogId(placeOrderResp.getOrderList()
					.get(0).getOrderInfoList().get(0).getCatalogId());

			applyvalidationBean.setRefundAmount(BigDecimal.ONE);

			applyvalidationBean.setRefundNumber(1);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();

			Logger.verifyEquals(ECode.FAILED201,
					applyvalidationCall.getString("code"), "验证返回码");

			Logger.verifyEquals("114", applyvalidationCall.getString("bcode"),
					"验证返回码");

			Logger.verifyEquals("申请退款金额不能大于实际可退款金额",
					applyvalidationCall.getString("msg"), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ApplyValidation_002() {
		Logger.start(true, "用户支付后接单前效验成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			Logger.comment("前置数据准备结束");
			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setCatalogId(placeOrderResp.getOrderList()
					.get(0).getOrderInfoList().get(0).getCatalogId());

			applyvalidationBean.setRefundAmount(BigDecimal.ONE);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();
			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("0", applyvalidationCall.getString("bcode"),
					"验证返回码");
			Logger.verifyEquals(false, applyvalidationCall.getData()
					.getBoolean("isValidationPass"), "验证isValidationPass");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ApplyValidation_003() {
		Logger.start(true, "商家接单前取消订单,效验成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 取消订单
			new OrderCallService().cancelOrder(orderId, userId);

			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setCatalogId(placeOrderResp.getOrderList()
					.get(0).getOrderInfoList().get(0).getCatalogId());

			applyvalidationBean.setRefundAmount(BigDecimal.ONE);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();
			Logger.verifyEquals(ECode.FAILED201,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals(
					"订单已取消，不能退货退款：" + applyvalidationBean.getOrderId(),
					applyvalidationCall.getString("msg"), "验证返回码");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ApplyValidation_004() {
		Logger.start(true, "商家接单后,退货退款校验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 付款
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);
			// 接单
			orderCallService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setCatalogId(placeOrderResp.getOrderList()
					.get(0).getOrderInfoList().get(0).getCatalogId());

			applyvalidationBean.setRefundAmount(BigDecimal.ONE);
			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals(true,
					applyvalidationCall.getData()
							.getBoolean("isValidationPass"),
					"验证isValidationPass");

			Logger.verifyEquals(0,
					(Integer) applyvalidationCall.getData()
							.get("refundFreight"), "验证refundFreight");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ApplyValidation_005() {
		Logger.start(true, "商家接单后取消订单,效验成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			// 接单
			new OrderCallService().acceptOrder(orderId, sellerId);
			// 取消订单
			new OrderCallService().cancelOrder(orderId, userId,
					CancelOrderTypeEnum.CustomerCancelOrder);
			Logger.comment("前置数据准备结束");
			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setCatalogId(placeOrderResp.getOrderList()
					.get(0).getOrderInfoList().get(0).getCatalogId());

			applyvalidationBean.setRefundAmount(BigDecimal.ONE);
			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();
			Logger.verifyEquals(ECode.FAILED201,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals(false, applyvalidationCall.getData()
					.getBoolean("isValidationPass"), "验证isValidationPass");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ApplyValidation_006() {
		Logger.start(false, "订单退货退款中,申请校验的金额小于等于可退款金额");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			// 接单
			new OrderCallService().acceptOrder(orderId, sellerId);
			// 退货退款同步中
			// 申请退款

			ApplySalesRefundRequestBean applysalesrefundrequestBean = new OrderCallService()
					.applySalesRefundRequestInJavaBean(orderId);

			applysalesrefundrequestBean.getSalesRefundInfoList().get(0)
					.setRefundAmount(BigDecimal.TEN);
			ApplySalesRefundRequestCall applysalesrefundrequestCall = new ApplySalesRefundRequestCall();
			applysalesrefundrequestCall.setData(applysalesrefundrequestBean);
			applysalesrefundrequestCall.callService();

			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setCatalogId(placeOrderResp.getOrderList()
					.get(0).getOrderInfoList().get(0).getCatalogId());

			applyvalidationBean.setRefundAmount(BigDecimal.ONE);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();
			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("0", applyvalidationCall.getString("bcode"),
					"验证返回码");
			Logger.verifyEquals(true,
					applyvalidationCall.getData()
							.getBoolean("isValidationPass"),
					"验证isValidationPass");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ApplyValidation_007() {
		Logger.start(false, "订单退货退款中,申请校验的金额大于最大可退款金额");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			// 退货退款同步中
			// 申请退款
			ApplySalesRefundRequestBean applysalesrefundrequestBean = new OrderCallService()
					.applySalesRefundRequestInJavaBean(orderId);

			applysalesrefundrequestBean.getSalesRefundInfoList().get(0)
					.setRefundAmount(totalPrice);

			ApplySalesRefundRequestCall applysalesrefundrequestCall = new ApplySalesRefundRequestCall();
			applysalesrefundrequestCall.setData(applysalesrefundrequestBean);
			applysalesrefundrequestCall.callService();

			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setCatalogId(placeOrderResp.getOrderList()
					.get(0).getOrderInfoList().get(0).getCatalogId());

			applyvalidationBean.setRefundAmount(BigDecimal.ONE);

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();
			Logger.verifyEquals(ECode.FAILED201,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("申请退款金额不能大于实际可退款金额",
					applyvalidationCall.getString("msg"), "验证msg");
			Logger.verifyEquals(false, applyvalidationCall.getData()
					.getBoolean("isValidationPass"), "申请退款金额不能大于实际可退款金额");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ApplyValidation_008() {
		Logger.start(true, "用户收货之后申请校验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			// 接单
			new OrderCallService().acceptOrder(orderId, sellerId);
			// 商家发货
			new OrderCallService().dispatched(orderId, sellerId);
			// 确认收货
			new OrderCallService().confirmReceive(userId, orderId);
			Logger.comment("前置数据准备结束");
			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setCatalogId(placeOrderResp.getOrderList()
					.get(0).getOrderInfoList().get(0).getCatalogId());

			applyvalidationBean.setRefundAmount(BigDecimal.ONE);
			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();
			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals(true,
					applyvalidationCall.getData()
							.getBoolean("isValidationPass"),
					"验证isValidationPass");
			Logger.verifyEquals(0,
					(Integer) applyvalidationCall.getData()
							.get("refundFreight"), "验证refundFreight");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ApplyValidation_009() {
		Logger.start(false, "订单号不存在申请效验");
		try {

			applyvalidationBean.setOrderId(11111);
			applyvalidationBean.setCatalogId("123");
			applyvalidationBean.setRefundAmount(BigDecimal.ONE);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();

			Logger.verifyEquals(ECode.FAILED201,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("订单不存在:" + applyvalidationBean.getOrderId(),
					applyvalidationCall.getString("msg"), "验证错误提示");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ApplyValidation_010() {
		Logger.start(false, "订单号为null申请效验");
		try {
			// applyvalidationBean.setOrderId(111111);
			applyvalidationBean.setCatalogId("123");
			applyvalidationBean.setRefundAmount(BigDecimal.ONE);
			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();

			Logger.verifyEquals(ECode.FAILED400,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("orderId:订单号不能为空",
					applyvalidationCall.getString("msg"), "验证错误提示");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ApplyValidation_014() {
		Logger.start(true, "商家发货后,退货退款校验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 付款
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);
			// 接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 发货
			orderCallService.dispatched(orderId, sellerId);
			Logger.comment("前置数据准备结束");
			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setCatalogId(placeOrderResp.getOrderList()
					.get(0).getOrderInfoList().get(0).getCatalogId());

			applyvalidationBean.setRefundAmount(BigDecimal.ONE);
			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();
			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals(true,
					applyvalidationCall.getData()
							.getBoolean("isValidationPass"),
					"验证isValidationPass");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ApplyValidation_015() {
		Logger.start(true, "确认收货15天后,退货退款校验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 付款
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);
			// 接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 发货
			orderCallService.dispatched(orderId, sellerId);
			// 确认收货
			orderCallService.confirmReceive(userId, orderId);
			new DefaultWapper().updateOrderConfirmedTimeByOrderId(orderId);
			Logger.comment("前置数据准备结束");
			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setCatalogId(placeOrderResp.getOrderList()
					.get(0).getOrderInfoList().get(0).getCatalogId());

			applyvalidationBean.setRefundAmount(BigDecimal.ONE);
			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();
			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals(false, applyvalidationCall.getData()
					.getBoolean("isValidationPass"), "验证isValidationPass");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ApplyValidation_016() {
		Logger.start(true, "付款之后,退货退款校验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 付款
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);

			Logger.comment("前置数据准备结束");
			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setCatalogId(placeOrderResp.getOrderList()
					.get(0).getOrderInfoList().get(0).getCatalogId());

			applyvalidationBean.setRefundAmount(BigDecimal.ONE);
			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();
			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals(false, applyvalidationCall.getData()
					.getBoolean("isValidationPass"), "验证isValidationPass");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ApplyValidation_017() {
		Logger.start(true, "商品申请退款金额大于(商品可退金额+订单总运费)");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId = order.getOrderId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();

			//第一个订单下的第一个商品
			List<OrderInfoPo> orderInfoList = order.getOrderInfoList();

			BigDecimal totalOrderInfoFreight = orderInfoList.stream()
					.map(item -> item.getFreight())
					.reduce(BigDecimal.ZERO, BigDecimal::add);

			// 付款
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);

			// 接单
			orderCallService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");

			//第一个商品
			OrderInfoPo orderInfoPo = orderInfoList.get(0);

			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setRefundNumber(orderInfoPo.getAmount());

			applyvalidationBean.setCatalogId(orderInfoPo.getCatalogId());

			applyvalidationBean.setRefundAmount(orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(orderInfoPo.getAmount()))
					.add(totalOrderInfoFreight).add(BigDecimal.ONE));

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals("201", applyvalidationCall.getString("code"),
					"验证返回码");

			Logger.verifyEquals(
					String.format("OrderId:%s, 申请退运费金额不能大于实际可退运费金额", orderId),
					applyvalidationCall.getString("msg"), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ApplyValidation_018() {

		Logger.start(true, "订单商品不是包邮,商品退款加退部分商品运费");

		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId = order.getOrderId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();

			//第一个订单下的第一个商品
			OrderInfoPo orderInfoPo = order.getOrderInfoList().get(0);

			String catalogId = orderInfoPo.getCatalogId();

			String productId = orderInfoPo.getProductId();

			int productNum = orderInfoPo.getAmount();

			BigDecimal productFreight = orderInfoPo.getFreight();

			BigDecimal refundProductFreight = productFreight
					.subtract(new BigDecimal(2));

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			// 付款
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);

			// 接单
			orderCallService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setCatalogId(orderInfoPo.getCatalogId());

			applyvalidationBean.setRefundNumber(orderInfoPo.getAmount());

			applyvalidationBean.setRefundAmount(refundProductFreight
					.add(refoundAmout));

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals("200", applyvalidationCall.getString("code"),
					"验证返回码");
			Logger.verifyEquals("null", applyvalidationCall.getString("msg"),
					"验证msg");

			DataUtil.verifyDecimalEquals(refundProductFreight, BigDecimal
					.valueOf((Double) applyvalidationCall.getData().get(
							"refundFreight")), "验证refundFreight");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ApplyValidation_019() {

		Logger.start(true, "订单商品不是包邮,商品退款及退超过商品的运费，但不超过订单总运费");

		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId = order.getOrderId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();

			//第一个订单下的第一个商品
			OrderInfoPo orderInfoPo = order.getOrderInfoList().get(0);

			String catalogId = orderInfoPo.getCatalogId();

			String productId = orderInfoPo.getProductId();

			int productNum = orderInfoPo.getAmount();

			BigDecimal productFreight = orderInfoPo.getFreight();

			BigDecimal refundProductFreight = productFreight
					.add(new BigDecimal(2));

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			// 付款
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);

			// 接单
			orderCallService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setCatalogId(orderInfoPo.getCatalogId());

			applyvalidationBean.setRefundAmount(refundProductFreight
					.add(refoundAmout));

			applyvalidationBean.setRefundNumber(orderInfoPo.getAmount());

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals("200", applyvalidationCall.getString("code"),
					"验证返回码");
			Logger.verifyEquals("null", applyvalidationCall.getString("msg"),
					"验证msg");

			DataUtil.verifyDecimalEquals(refundProductFreight, BigDecimal
					.valueOf((Double) applyvalidationCall.getData().get(
							"refundFreight")), "验证refundFreight");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ApplyValidation_020() {

		Logger.start(true, "退款商品数量大于实际数量");

		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId = order.getOrderId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();

			//第一个订单下的第一个商品
			OrderInfoPo orderInfoPo = order.getOrderInfoList().get(0);

			BigDecimal productFreight = orderInfoPo.getFreight();

			BigDecimal refundProductFreight = productFreight
					.add(new BigDecimal(2));

			// 付款
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);

			// 接单
			orderCallService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setCatalogId(orderInfoPo.getCatalogId());

			applyvalidationBean.setRefundAmount(refundProductFreight);

			applyvalidationBean.setRefundNumber(orderInfoPo.getAmount() + 1);

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals("201", applyvalidationCall.getString("code"),
					"验证返回码");

			Logger.verifyEquals(String.format(
					"OrderId:%s(refundNumber:%s), 申请退商品数量不能大于实际商品数量",
					applyvalidationBean.getOrderId(),
					applyvalidationBean.getRefundNumber()), applyvalidationCall
					.getString("msg"), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ApplyValidation_021() {

		Logger.start(true, "订单商品不是包邮,申请单个商品退款");

		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId = order.getOrderId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();

			//第一个订单下的第一个商品
			OrderInfoPo orderInfoPo = order.getOrderInfoList().get(0);

			int productNum = orderInfoPo.getAmount();

			BigDecimal productFreight = orderInfoPo.getFreight();

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			//单件商品可退金额

			BigDecimal oneProRefund = refoundAmout.divide(new BigDecimal(
					productNum), 2, BigDecimal.ROUND_DOWN);

			// 付款
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);

			// 接单
			orderCallService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setCatalogId(orderInfoPo.getCatalogId());

			applyvalidationBean.setRefundNumber(1);

			applyvalidationBean.setRefundAmount(oneProRefund);

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals("200", applyvalidationCall.getString("code"),
					"验证返回码");
			Logger.verifyEquals("null", applyvalidationCall.getString("msg"),
					"验证msg");

			DataUtil.verifyDecimalEquals(BigDecimal.ZERO, BigDecimal
					.valueOf((Integer) applyvalidationCall.getData().get(
							"refundFreight")), "验证refundFreight");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ApplyValidation_022() {

		Logger.start(true, "订单商品不是包邮,申请单个商品退款加部分商品运费");

		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId = order.getOrderId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();

			//第一个订单下的第一个商品
			OrderInfoPo orderInfoPo = order.getOrderInfoList().get(0);

			String catalogId = orderInfoPo.getCatalogId();

			String productId = orderInfoPo.getProductId();

			int productNum = orderInfoPo.getAmount();

			BigDecimal productFreight = orderInfoPo.getFreight();

			BigDecimal refundProductFreight = productFreight
					.subtract(new BigDecimal(2));

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			//单件商品可退金额

			BigDecimal oneProRefund = refoundAmout.divide(new BigDecimal(
					productNum), 2, BigDecimal.ROUND_DOWN);

			// 付款
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);

			// 接单
			orderCallService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setCatalogId(orderInfoPo.getCatalogId());

			applyvalidationBean.setRefundNumber(1);

			applyvalidationBean.setRefundAmount(oneProRefund
					.add(refundProductFreight));

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals("200", applyvalidationCall.getString("code"),
					"验证返回码");
			Logger.verifyEquals("null", applyvalidationCall.getString("msg"),
					"验证msg");

			DataUtil.verifyDecimalEquals(refundProductFreight, BigDecimal
					.valueOf((Double) applyvalidationCall.getData().get(
							"refundFreight")), "验证refundFreight");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ApplyValidation_023() {

		Logger.start(true, "订单商品不是包邮,申请单个商品退款加上不超过订单总运费");

		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId = order.getOrderId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();

			//第一个订单下的第一个商品
			OrderInfoPo orderInfoPo = order.getOrderInfoList().get(0);

			int productNum = orderInfoPo.getAmount();

			BigDecimal productFreight = orderInfoPo.getFreight();

			BigDecimal refundProductFreight = productFreight
					.add(new BigDecimal(2));

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			//单件商品可退金额

			BigDecimal oneProRefund = refoundAmout.divide(new BigDecimal(
					productNum), 2, BigDecimal.ROUND_DOWN);

			// 付款
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);

			// 接单
			orderCallService.acceptOrder(orderId, sellerId);

			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setCatalogId(orderInfoPo.getCatalogId());

			applyvalidationBean.setRefundNumber(1);

			applyvalidationBean.setRefundAmount(oneProRefund
					.add(refundProductFreight));

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals("200", applyvalidationCall.getString("code"),
					"验证返回码");
			Logger.verifyEquals("null", applyvalidationCall.getString("msg"),
					"验证msg");

			DataUtil.verifyDecimalEquals(refundProductFreight, BigDecimal
					.valueOf((Double) applyvalidationCall.getData().get(
							"refundFreight")), "验证refundFreight");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ApplyValidation_024() {

		Logger.start(true, "订单商品不是包邮,申请单个商品退款加订单总运费");

		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal orderFreight = order.getFreight();

			int orderId = order.getOrderId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();

			//第一个订单下的第一个商品
			OrderInfoPo orderInfoPo = order.getOrderInfoList().get(0);

			int productNum = orderInfoPo.getAmount();

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			//单件商品可退金额

			BigDecimal oneProRefund = refoundAmout.divide(new BigDecimal(
					productNum), 2, BigDecimal.ROUND_DOWN);

			// 付款
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);

			// 接单
			orderCallService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setCatalogId(orderInfoPo.getCatalogId());

			applyvalidationBean.setRefundNumber(1);

			applyvalidationBean.setRefundAmount(oneProRefund.add(orderFreight));

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals("200", applyvalidationCall.getString("code"),
					"验证返回码");
			Logger.verifyEquals("null", applyvalidationCall.getString("msg"),
					"验证msg");

			DataUtil.verifyDecimalEquals(orderFreight, BigDecimal
					.valueOf((Double) applyvalidationCall.getData().get(
							"refundFreight")), "验证refundFreight");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ApplyValidation_025() {

		Logger.start(true, "订单商品不是包邮,申请单个商品退款加上超过订单总运费");

		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal orderFreight = order.getFreight();

			int orderId = order.getOrderId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();

			//第一个订单下的第一个商品
			OrderInfoPo orderInfoPo = order.getOrderInfoList().get(0);

			int productNum = orderInfoPo.getAmount();

			BigDecimal refundProductFreight = orderFreight
					.add(new BigDecimal(2));

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			//单件商品可退金额

			BigDecimal oneProRefund = refoundAmout.divide(new BigDecimal(
					productNum), 2, BigDecimal.ROUND_DOWN);

			// 付款
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);

			// 接单
			orderCallService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setCatalogId(orderInfoPo.getCatalogId());

			applyvalidationBean.setRefundNumber(1);

			applyvalidationBean.setRefundAmount(oneProRefund
					.add(refundProductFreight));

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals("201", applyvalidationCall.getString("code"),
					"验证返回码");
			Logger.verifyEquals(
					String.format("OrderId:%s, 申请退运费金额不能大于实际可退运费金额", orderId),
					applyvalidationCall.getString("msg"), "验证msg");

			DataUtil.verifyDecimalEquals(BigDecimal.ZERO, BigDecimal
					.valueOf((Integer) applyvalidationCall.getData().get(
							"refundFreight")), "验证refundFreight");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ApplyValidation_026() {
		Logger.start(true, "订单锁定后申请效验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			new OrderCallService().markOrderLock(orderId, 1);

			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setCatalogId(placeOrderResp.getOrderList()
					.get(0).getOrderInfoList().get(0).getCatalogId());

			applyvalidationBean.setRefundAmount(BigDecimal.ONE);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();

			Logger.verifyEquals(ECode.FAILED201,
					applyvalidationCall.getString("code"), "验证返回码");

			Logger.verifyEquals("该订单已被洋码头客服锁定，暂时无法对该订单进行后续操作",
					applyvalidationCall.getString("msg"), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ApplyValidation_027() {
		Logger.start(true, "虚拟商品不能发起退货退款");

		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();

			PlaceOrderResp placeOrderResp = BargainGroupService
					.placeVirtualProduct();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId = order.getOrderId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();

			//第一个订单下的第一个商品
			OrderInfoPo orderInfoPo = order.getOrderInfoList().get(0);

			String catalogId = orderInfoPo.getCatalogId();

			String productId = orderInfoPo.getProductId();

			int productNum = orderInfoPo.getAmount();

			BigDecimal productFreight = orderInfoPo.getFreight();

			BigDecimal refundProductFreight = productFreight
					.subtract(new BigDecimal(2));

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			// 付款
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);

			// 接单
			orderCallService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			applyvalidationBean.setCatalogId(orderInfoPo.getCatalogId());

			applyvalidationBean.setRefundNumber(orderInfoPo.getAmount());

			applyvalidationBean.setRefundAmount(refundProductFreight
					.add(refoundAmout));

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals("201", applyvalidationCall.getString("code"),
					"验证返回码");

			Logger.verifyEquals("102", applyvalidationCall.getString("bcode"),
					"验证bcode");
			Logger.verifyEquals("虚拟商品不能发起退货退款",
					applyvalidationCall.getString("msg"), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
